package com.yh.lq.boot;

import com.yh.lq.websocket.LQWebSocketHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@ComponentScan(
        basePackages = {"com.yh.lq"}
)
@EnableWebSocket
@EnableConfigurationProperties({LQProperties.class, EventProperties.class})
@Import(LQBean.class)
@Slf4j
public class LQAutoConfiguration implements WebSocketConfigurer {


    @Autowired
    com.yh.lq.boot.LQProperties LQProperties;


    @Autowired
    LQWebSocketHandler webSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        log.info("注册socket");
        registry.addHandler(webSocketHandler, LQProperties.getUrl()).setAllowedOrigins("*");
    }


}
